﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WBrowser
{
    public partial class Post : Form
    {
        public Links _parentForm;
        public DataGridViewRow _row;
        public Post(Links parent)
        {
            InitializeComponent();
            _parentForm = parent;
        }

        public Post(Links parent, DataGridViewRow dr)
        {
            InitializeComponent();
            _parentForm = parent;
            _row = dr;
        }

        private void Post_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'mpconfigDataSet.Languages' table. You can move, or remove it, as needed.
            this.languagesTableAdapter.Connection.ConnectionString = GeneralClass.ConnectString();
            this.languagesTableAdapter.Fill(this.mpconfigDataSet.Languages);
            textBoxCreateDate.Text = DateTime.Now.ToShortDateString();

            textBoxTitle.Text = _row.Cells["titleDataGridViewTextBoxColumnPost"].Value.ToString();
            richTextBoxContent.Text = _row.Cells["contentDataGridViewTextBoxColumnPost"].Value.ToString();
            comboBox1.SelectedIndex = languagesBindingSource.Find("language", _row.Cells["languageDataGridViewTextBoxColumnPost"].Value.ToString());
            textBoxCreateDate.Text = _row.Cells["createDataGridViewTextBoxColumnPost"].Value.ToString();
            btnAdd.Text = "Update";
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (btnAdd.Text == "Update")
            {
                this._parentForm.AddPost(textBoxTitle.Text, richTextBoxContent.Text, comboBox1.Text, textBoxCreateDate.Text);
            }
            else
                this._parentForm.AddPost(textBoxTitle.Text, richTextBoxContent.Text, comboBox1.Text, textBoxCreateDate.Text);
            this.Close();
        }
    }
}
